package com.lanou3g.springboot_demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class RedisService {

	// SpringBoot会自动帮我们装配RedisConnectionFactory, StringRedisTemplate, RedisTemplate这几个类
	// 自动装配的属性可以直接注入到我们的类中使用
	@Autowired
//	private StringRedisTemplate redisTemplate;	//专门操作String类型的key\value
	private RedisTemplate redisTemplate;

	public void set(String key, String value) {
		redisTemplate.opsForValue().set(key, value);
	}

	public Object get(String key) {
		return redisTemplate.opsForValue().get(key);
	}
}
